package com.example.jixeishi1.controller;

import com.example.jixeishi1.entity.Orders;
import com.example.jixeishi1.service.OrdersService;


import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;

@Controller
public class OrdersControllr {

    @Autowired
    OrdersService service;

    /*
    state 是状态
    order 是订单
     */
//    @Param("state") String state,
    @RequestMapping("/state")
    public String statelist(@Param("id") int id, @Param("state") String state,
                            @RequestParam(defaultValue = "1") int page,
                            @RequestParam(defaultValue = "00") String market_order,
                            ModelMap map){

        System.out.println("list页面");
//        状态
        if(!market_order.equals("00")){
            System.out.println("id是:"+id+"状态是:"+state+"页码"+page+"订单类型:"+market_order);
            System.out.println("4");
            Orders o1=new Orders();
            o1.setId(id);
            o1.setStatus(state);
            o1.setMarketorder(market_order);
            System.out.println(o1);
            PageInfo pageInfo=service.statelist(page,o1);
            map.put("pageInfo",pageInfo);
            List list=service.funstate2(id,page,state,market_order);
            map.put("list",list);
        }else {
//            订单
            System.out.println("id是:"+id+"状态是:"+state+"页码"+page+"订单类型:"+market_order);
            System.out.println("3");
            Orders o=new Orders();
            o.setId(id);
            o.setStatus(state);
            PageInfo pageInfo=service.statelist(page,o);
            map.put("pageInfo",pageInfo);
            List list=service.funstate1(id,page,state);
            map.put("list",list);
        }
            return "orders";
    }
//全部订单
    @RequestMapping("/infostate")
    public String infostate(@Param("id") int id,@RequestParam(defaultValue = "1") int page
                                        ,ModelMap map){
        System.out.println("id:"+id+"页码"+page);
        Orders o=new Orders();
        o.setId(id);
        PageInfo pageInfo=service.infostate(page,o);
        map.put("pageInfo",pageInfo);
        List list=service.funstate3(id,page);
        map.put("list",list);
        return "orders";
    }
    //搜索框
    @RequestMapping("/ssk")
    public String orderlist1(@Param("id") int id,@Param("order") String order,
                            @RequestParam(defaultValue = "1") int page,ModelMap map1){
        System.out.println("id"+id+"订单:"+order+"页码"+page);
        HashMap map=new HashMap();
        map.put("id",id);
        map.put("order_no",order);
        PageInfo pageInfo=service.ssstate(page,map);
        map1.put("pageInfo",pageInfo);
        List list=service.funstate3(id,page);
        map1.put("list",list);
        return "orders";
    }
    @RequestMapping("delorder")
    public String delorder(int id,int u_id){
//        u_id 订单id  id是用户id
        System.out.println("id"+u_id+"uzid"+id);
        HashMap map=new HashMap();
        map.put("id",u_id);
        map.put("user_id",id);
        int n=service.delstate(map);
        return "redirect:/infostate?id="+id;
    }

    @RequestMapping("ddxqlist")
    public String ddxqlist(int id,int u_id,ModelMap map1){
//        u_id 订单id  id是用户id
        System.out.println("id"+u_id+"uzid"+id);
        HashMap map=new HashMap();
        map.put("id",u_id);
        map.put("user_id",id);
        List list=service.ddxxlist(map);
        System.out.println(list);
        map1.put("list",list);
        return "xiangqing";
    }
}
